﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Task02
{
    class File
    {
        public string Name { get; private set; }
        public long Size { get; private set; }

        public File(string name)
        {
            this.Name = name;
            FileInfo info = new FileInfo(name);
            this.Size = info.Length;
        }
    }

    class Folder
    {
        public string Name { get; private set; }
        public File[] Files { get; private set; }
        public Folder[] ChildFolders { get; private set; }
        public long ThisFoldersFilesSize { get; private set; }
        public long ThisFoldersFilesSizeAndChildFoldersFilesSize { get; private set; }

        public Folder(string name)
        {
            try
            {
                this.Name = name;
                string[] files = Directory.GetFiles(name);
                this.Files = new File[files.GetLength(0)];
                this.ThisFoldersFilesSize = 0;

                for (int i = 0; i < files.GetLength(0); i++)
                {
                    this.Files[i] = new File(files[i]);
                    this.ThisFoldersFilesSize += this.Files[i].Size;
                }

                string[] folders = Directory.GetDirectories(name);
                this.ChildFolders = new Folder[folders.GetLength(0)];

                this.ThisFoldersFilesSizeAndChildFoldersFilesSize = 0;
                for (int i = 0; i < folders.GetLength(0); i++)
                {
                    this.ChildFolders[i] = new Folder(folders[i]);
                    this.ThisFoldersFilesSizeAndChildFoldersFilesSize += ChildFolders[i].ThisFoldersFilesSize;
                    this.ThisFoldersFilesSizeAndChildFoldersFilesSize += ChildFolders[i].ThisFoldersFilesSizeAndChildFoldersFilesSize;
                }
            }
            catch
            {
                this.ThisFoldersFilesSize = 0;
                this.ThisFoldersFilesSizeAndChildFoldersFilesSize = 0;
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string path = "C:\\Windows";
            Folder root = new Folder(path);

            Console.WriteLine(root.ThisFoldersFilesSizeAndChildFoldersFilesSize);
        }
    }
}
